package com.luo.bbs.front.webapi.controller;


import com.example.bbs.front.service.ICommentService;
import com.luo.common.restful.JsonResult;

import com.luo.pojo.comment.dto.CommentDTO;
import com.luo.pojo.comment.vo.CommentVO;
import com.luo.pojo.tag.entity.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章评论表 前端控制器
 * </p>
 *
 * @author bin.cn
 * @since 2023-01-19
 */
@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @PostMapping("/post")
    public JsonResult postComment(@Validated CommentDTO commentDTO){
        log.debug("前端参数:{}",commentDTO);
        CommentVO commentVO = commentService.postComment(commentDTO);
        log.debug("测试发表评论");
        return JsonResult.ok(commentVO);
    }

    /**
     * 通过帖子Id查询评论树结构
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public JsonResult getComment(@PathVariable Integer id){
        List<CommentVO> commentVOList = commentService.commentTree(id);
        return JsonResult.ok(commentVOList);
    }

    /**
     * 查询用户评论数
     */
    @GetMapping("/count/{userId}")
    public JsonResult getCountByUser(@PathVariable Integer userId){
        Integer count = commentService.getCountByUser(userId);
        return JsonResult.ok(count);
    }


}
